# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=waf

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.15
pkgrel=1
pkgdesc="General-purpose build system modelled after Scons (mingw-w64)"
arch=('any')
license=('BSD')
url="http://code.google.com/p/waf/"
makedepends=("setconf")
depends=("${MINGW_PACKAGE_PREFIX}-python3")
options=('!emptydirs')
source=("http://${_realname}.googlecode.com/files/${_realname}-$pkgver.tar.bz2"
    waflib.patch)
sha256sums=('49780032ed2ac0e118030af329cbd5883d2b9cb9831fc632a3e7b2bfd99d3f1e'
            'c7a7f938483db968e33bd1cdccb71cae199fd67afbc2baa1ec25e2ad4243e9bd')

prepare() {
  cd "${_realname}-$pkgver"
  patch -p1 -i ${srcdir}/waflib.patch
  # Extracting license
  head -n 30 waf | tail -n 25 > LICENSE
  # Python 3 fix
  sed -i '0,/env python/s//python3/' waf
}

build() {
  cd ${_realname}-$pkgver
  plain "Configure ..."
  ${MINGW_PREFIX}/bin/python3 ./waf-light configure --prefix=${MINGW_PREFIX}
  plain "Make waf ..."
  ${MINGW_PREFIX}/bin/python3 ./waf-light --make-waf
}

package() {
  cd "${_realname}-$pkgver"

  ${MINGW_PREFIX}/bin/python3 ./waf-light install -f --destdir="$pkgdir" \
    --tools='compat,compat15,ocaml,go,cython,scala,erlang,cuda,gcj,boost,pep8,eclipse'

  install -Dm755 waf "${pkgdir}${MINGW_PREFIX}/bin/waf"

  # Force the generation of .waf.admin files
  cd demos/c
  "${pkgdir}${MINGW_PREFIX}/bin/waf" configure build >& /dev/null
  cd ../..

  # Fix weird directory placement (FS#38216, FS#38300)
  mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/waf"
  mv "${pkgdir}${MINGW_PREFIX}/bin/.waf3-$pkgver-"* "${pkgdir}${MINGW_PREFIX}/lib/waf/"
  setconf "${pkgdir}${MINGW_PREFIX}/bin/waf" base '"${MINGW_PREFIX}/lib/waf"'

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/$pkgname/LICENSE"

}
